package com.youth.routercore

class InterceptorController {
    private val interceptorList = mutableListOf<RouterInterceptor>()

    fun addInterceptor(interceptor: RouterInterceptor) {
        interceptorList.add(interceptor)
    }

    fun removeInterceptor(interceptor: RouterInterceptor) {
        interceptorList.remove(interceptor)
    }

    fun shouldIntercept(routerPathRequest: RouterPathRequest): RouterInterceptor? {
        val interceptors = mutableListOf<RouterInterceptor>()
        interceptors.addAll(interceptorList)
        val intercept = interceptors.find { interceptor ->
            interceptor.shouldIntercept(routerPathRequest)
        }
        return intercept
    }
}